<?php
/**
 * Created by PhpStorm.
 * User: alei
 * Date: 11/5/2017 AD
 * Time: 16:58
 */
namespace App\Models\Mysql;

//use Illuminate\Database\Eloquent\Model;
use App\Models\Traits\BaseDBMethod;

class ctranklist
{
	use BaseDBMethod;
	//数据库连接配置项，见config/database.php
	const DATABASE_CONF = 'lqyw_mysql';
	//pre_ct_ui 首页轮播图所在表
	const TABLE_NAME = 'pre_forum_pollvoter';

	//数据库连接配置项，见config/database.php
	//如果需要用ORM，需要设置此项
//	protected $connection = self::DATABASE_CONF;
	//表名，如果需要用ORM，需要设置此项
//	protected $table = self::TABLE_NAME;

	public static function getTranslateTotalRankListData($start, $count)
	{
		$r=self::getConnObj()->select(
		    "select cm.uid, cm.username userName, credits". 
			" from pre_common_member cm". 
			" where credits>0".
			" order by credits desc".
			" limit ".$start.", ".$count);
		return $r;
	}
	
	public static function getTranslateLatestRankListData($ct_taskid, $start, $count)
	{
		$r=self::getConnObj()->select(
		    "select cm.uid, cm.username userName, ct_tran.ctcredit credits". 
			" from pre_common_member cm, pre_ct_translatedtext ct_tran, pre_forum_thread ft". 
			" where ct_tran.tid=ft.tid and cm.uid=ft.authorid and ct_tran.taskid=".$ct_taskid.
			" and ct_tran.ctcredit>0".
			" order by ct_tran.ctcredit desc, ft.dateline asc".
			" limit ".$start.", ".$count);
		return $r;
	}
	
	public static function getVoteTotalRankListData($start, $count)
	{
		$r=self::getConnObj()->select(
		    "select cm.uid, cm.username userName, cmc.ctcredits1 credits". 
			" from pre_common_member cm, pre_common_member_count cmc". 
			" where cm.uid=cmc.uid and cmc.ctcredits1>0".
			" order by cmc.ctcredits1 desc".
			" limit ".$start.", ".$count);
		return $r;
	}

	public static function getVoteLatestRankListData($polltid, $start, $count)
	{
		$r=self::getConnObj()->select(
			"select cm.uid, cm.username userName, fpv.votercredits credits". 
			" from pre_common_member cm, pre_forum_pollvoter fpv". 
			" where cm.uid=fpv.uid and fpv.tid=".$polltid.
			" and fpv.votercredits>0".
			" order by fpv.votercredits desc, fpv.dateline asc".
			" limit ".$start.", ".$count);
		return $r;
	}
	
}